<?php
declare(strict_types=1);

namespace Service\MemberService\Volidate;

use Service\BaseService;
use App\Model\BbcModel\Member;
use Service\PayService\CashPayService;
use Service\Code\Normal;


class BalanceVolidate extends BaseService
{
    public function checkchargedata(array $param = []){
        if(empty($param['mid'])){
            return Normal::returnCode(Normal::FAIL, '会员信息必传');
        }
        $memberinfo = Member::instance()->info(['mid'=>$param['mid']]);
        if(empty($memberinfo)){
            return Normal::returnCode(Normal::FAIL, '会员信息错误');
        }
        $param['memberinfo'] = $memberinfo;
        if(empty($param['money'])){
            return Normal::returnCode(Normal::FAIL, '金额不能为空');
        }
        if(empty($param['point'])){
            return Normal::returnCode(Normal::FAIL, '积分不能为空');
        }
        if(empty($param['pay'])){
            return Normal::returnCode(Normal::FAIL, '支付信息不能为空');
        }
        $pay = @json_decode($param['pay'],TRUE);
        if( empty($pay) ) {
            return Normal::returnCode(Normal::FAIL, '支付方式不能为空');
        }
        if(count($pay) > 1){
            return Normal::returnCode(Normal::FAIL, '会员储值积分不能混合支付');
        }
        $payerCheck = CashPayService::instance()->getPayChannel($pay, $param, CashPayService::PRODUCT_BALANCE_ORDER_PAY);
        if( $payerCheck['code'] != Normal::SUC ) {
            return $payerCheck;
        }
        
        $param          = $payerCheck['data'];
        return Normal::returnCode(Normal::SUC, '成功',$param);
    }
}